﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.IServices;
using Api.Model;
using Api.Model.Dto.ArticleTypeDto;
using Api.Model.Model;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ArticleTypeController : ApiBaseController
    {
        private readonly IArticleTypeServices _articleTypeServices;
        private readonly IMapper _mapper;

        public ArticleTypeController(IArticleTypeServices articleTypeServices,IMapper mapper)
        {
            _articleTypeServices = articleTypeServices;
            _mapper = mapper;
        }
        [HttpPost]
        public async Task<GetArticleTypeOutput> CreateArticleTypeAsync([FromForm]CreateArticleTypeInput input)
        {
           
            return await _articleTypeServices.AddArticleTypeAsync(input);
        }
        [HttpGet]
        public async Task<List<GetArticleTypeOutput>> GetArticleTypeListAsync([FromQuery]GetArticleTypeInput input)
        {
            List<ArticleType> res = await _articleTypeServices.GetArticleTypeListAsync(input);
            var ArticleTypes = _mapper.Map<List<GetArticleTypeOutput>>(res);
            return ArticleTypes;
        }
        [HttpGet]
        public async Task<Dictionary<int,GetArticleTypeOutput>> GetArticleTypeDicAsync([FromQuery]GetArticleTypeInput input)
        {
            List<ArticleType> res = await _articleTypeServices.GetArticleTypeListAsync(input);
            var ArticleTypes = _mapper.Map<List<GetArticleTypeOutput>>(res);
            return ArticleTypes.ToDictionary(x => x.Id);
        }
        [HttpPut]
        public async Task UpdateArticleTypeAsync([FromForm]UpdateArticleTypeInput input)
        {
            await _articleTypeServices.UpdateArticleTypeAsync(input);
        }
        [HttpDelete]
        public async Task DeleteArticleTypeAsync(int? id)
        {
            await _articleTypeServices.DeleteArticleTypeAsync(id.Value);
        }
    }
}